import React, { Component } from 'react';
import Style from './index.module.scss';
import HomeLinkModel from '../../../../models/homeLink'
import { Card, Divider } from 'antd';

interface StateInterface {
  dataArr: Array<HomeLinkModel>
}

interface PropsInterface {
}

class WebHomeLinks extends Component<PropsInterface, StateInterface> {

  state: Readonly<StateInterface> = {
    dataArr: []
  }

  componentDidMount() {
    this.getAllModel()
  }

  getAllModel() {
    HomeLinkModel.getModels().then((data: any) => {
      this.setState(() => {
        return {
          dataArr: data
        }
      })
    }).catch(() => { })
  }

  render(): React.ReactElement<any, string | React.JSXElementConstructor<any>> | string | number | {} | React.ReactNodeArray | React.ReactPortal | boolean | null | undefined {
    return (
      <div className={'w-content-box'}>
        <Divider>项目链接</Divider>
        <Card className={'w-content-box'}>
          <ul className={`${Style['home-links']}`}>
            {
              this.state.dataArr.map((item: HomeLinkModel) => {
                return (
                  <li className={Style['link-item']} key={item._id}>
                    <a rel="noopener noreferrer" className={Style.link} target='_blank' href={item.link}>{item.title}</a>
                  </li>
                )
              })
            }
          </ul>
        </Card>
      </div>
    );
  }
}

export default WebHomeLinks;
